<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/7 0007
 * Time: 15:59
 */

namespace app\admin\controller;



use app\admin\model\Admin;
use app\admin\model\Adminlog;
use think\Controller;
use think\Db;


class Login extends Controller
{

    public function index()
    {
      return $this->fetch();
    }
    public function login()
    {
        $where=['username'  => $_POST ["username"]];
        $result=Db::name('Admin')->where($where)->find();

        if ($result) {

        } else {
            $this->error ( "登录失败", url ( "admin/Login/index" ) );
        }
        $where=['password' => md5($_POST ["password"])];
        $result=Db::name('Admin')->where($where)->find();

        if ($result) {
            session('admin',$result);
          Adminlog::adminlog('登录成功');


            $this->success ( "登录成功", url ( "admin/Index/index" ) );

        } else {
            $this->error ( "登录失败", url ( "admin/Login/index" ) );
        }
    }
    public function logout()
    {
        session("admin",null);
        $this->success ( "注销成功", url ( "admin/Login/index" ) );
    }
}
